<?php
if(checkAdmin()){
?>
	<script language="javascript" src="js/graphics.js"></script>
    <?php
        if(isset($_POST['submit'])){
			if(strlen($_POST['shapeName']) != 0){
				require_once("classes/Shape.class.php");
				$color = new Shape($_POST);
				$color->save();
			}
			else
			{
				echo '<div class="centered">'.getErrMess(36).'</div>';
			}
        }
    ?>
    <h2>Gérer les formes</h2>
    <p>Pour ajouter une forme il faut préalablement ajouter la fonction permettant de la dessiner dans le fichier graphics.js (myShapeFunction(redQuantity, greenQuantity, blueQuantity, idCreatedCanvas, size).</p>
    <div class="centered">
        <div id="elementList">
             <?php
                require_once("classes/HumeurDatabase.class.php");
                require_once("classes/Galery.class.php");
                require_once("classes/Shape.class.php");
                $bd = new HumeurDatabase();
                $bd->connect();
                $gallery = new Galery('',error("Aucune couleur n'est disponible pour le moment."));
                $allShapes = $bd->selectAll("shapes");
                while($shapeData = mysql_fetch_assoc($allShapes)){
                    $shape = new Shape($shapeData);
                    $gallery->push($shape);
                }
                echo $gallery;
            ?>
            <div style="padding-top:0;padding-bottom:0;" class="centered existingColorBloc">
                <div class="colorForm">
                    <form action="" method="post">
                        <input style="width:80px;height:13px;" type="text" name="shapeName" placeholder="Forme" /><br/>
                        <div id="newShape"></div>
                        <input style="width:80px;height:13px;" value="" placeholder="Fonction JS" onkeyup="createShape('newShape',document.getElementById('javascriptFunction').value,0,0,0)" type="text" name="javascriptFunction" id="javascriptFunction"/><br/>
                        <input type="submit" name="submit">
                    </form>
                </div>
            </div>
        </div>
    </div>
    <div class="centered"><span class="buttonBloc grey"><a href="index.php?module=myaccount"><img src="img/back.png" alt="Retour"/>Retour au compte</a></span></div>
    <script>createShape('newShape',document.getElementById('javascriptFunction').value,0,0,0);</script>
<?php
}
?>